# Scrapy settings for magnet_link project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://docs.scrapy.org/en/latest/topics/settings.html
#     https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://docs.scrapy.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'temp'

SPIDER_MODULES = ['temp.spiders']
NEWSPIDER_MODULE = 'temp.spiders'

# MONGODB 主机名
DB_HOST = "127.0.0.1"
# MONGODB 端口号
DB_PORT = 3306
# 数据库名称
DB_DBNAME = "hua"
#用户名
DB_USER = 'root'
#密码
DB_PASSWORF = '123456'
#编码
DB_CHARSET = 'utf8'

# Crawl responsibly by identifying yourself (and your website) on the user-agent
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.54 Safari/536.5'

# Obey robots.txt rules
ROBOTSTXT_OBEY = False
#增加并发
# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
DOWNLOAD_DELAY = 1
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
COOKIES_ENABLED = False
FEED_EXPORT_ENCODING = 'utf-8'
# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False
REDIRECT_ENABLED = False
HTTPERROR_ALLOWED_CODES = [301,302,500,400,401,404,403,522,520,429]
# Override the default request headers:
DEFAULT_REQUEST_HEADERS = {
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'Accept-Language': 'en',
  # 'Authentication':'USERID aHVhNV90ZXh0OmQ1OXZGNDlXUXdmejZtRVl1TDBWbms3MzJ0eUFDRE9IOjBEMThBRjU4LTBDMkUtQjM3QS02NjkwLTU5RkU0RDdDRTEzMDow'
}


#LOG_LEVEL = 'INFO'
#禁止重试
RETRY_ENABLED = False
# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
SPIDER_MIDDLEWARES = {
    # 'magnet_link.middlewares.MagnetLinkSpiderMiddleware': 543
   # 'magnet_link.middlewares.ProcessAllExceptionMiddleware':1,
   # 'scrapy.spidermiddlewares.httperror.HttpErrorMiddleware':None
}

# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {
   'temp.selenium_middleware.SeleniumMiddleware': 543
    # 'scrapy.spidermiddlewares.httperror.HttpErrorMiddleware':None
}
#没效果的配置
#HTTPERROR_ALLOWED_CODES = [404,500,501,502,403]
# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
#}
RANDOMIZE_DOWNLOAD_DELAY=True
DOWNLOAD_DELAY = 2# 250 ms of delay
DOWNLOAD_TIMEOUT = 90

SELENIUM_TIMEOUT = 20
PHANTOMJS_SERVICE_ARGS = ['--load-images=false', '--disk-cache=true']
# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
# FILE_STORE=''
ITEM_PIPELINES = {
   #'temp.pipelines.MagnetLinkPipeline': 300,
   'temp.files_pipelines.myfilesPipeline': 1,
}

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHROTTLE_ENABLED = True
# The initial download delay
#AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
#AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
